<?php

namespace App\Events;

use App\Events\SolveProblem;
use App\Timeline;
use App\Utils;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class CreateTimeLine
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  SolveProblem $event
     * @return void
     */
    public function handle(SolveProblem $event)
    {
        //
        $user = $event->user;
        $task = $event->task;

        $user->msgcnt += 1;
        $user->solveNum += 1;
        $user->score += $task->score;
        $user->save();

        $timeline = [
            'url' => Utils::id2url($task->id),
            'title' => $task->title,
            'created_at' => date('Y-m-d H:i:s', time()),
        ];

        Timeline::createTimeline($user->id, 1, $timeline, time());


    }
}
